package com.zhiwang.planet.ui

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import com.zhiwang.planet.R
import com.zhiwang.planet.util.TokenManager
import com.zhiwang.planet.util.Utils
import com.zhiwang.planet.util.quickStartActivity
import com.zhiwang.planet.util.suicideAfterTransition
import kotlinx.android.synthetic.main.activity_welcome.*

class WelcomeActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_welcome)
        if (TokenManager.isFirstTimeInstall().not()) {
            quickStartActivity(SplashActivity::class.java)
            finish()
        }
        com.zhiwang.planet.util.Utils.setStatusBar(this, false, false)
        viewPager.adapter = XmlPageAdapter(3)
        viewPager.offscreenPageLimit = 2
        circleindicator.setViewPager(viewPager)
    }


    fun startTravel(v: View) {
        quickStartActivity(SplashActivity::class.java)
        suicideAfterTransition()
    }
}

class XmlPageAdapter(val itemCount: Int) : androidx.viewpager.widget.PagerAdapter() {

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        container.removeViewAt(position)
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        return container.getChildAt(position)
    }

    override fun isViewFromObject(p0: View, p1: Any) = p0 == p1

    override fun getCount(): Int = itemCount

}
